package com.dayuanit.dy16.atm.boatm.util;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DecimalFormat;

public class MoneyUtils {

    public static int plus(int number, double amount) {
        BigDecimal one = new BigDecimal(number);
        BigDecimal two = BigDecimal.valueOf(amount);
        two = two.multiply(new BigDecimal(100));
        return one.add(two).intValue();
    }

    public static String div(double n1, double n2) {
        BigDecimal bigDecimal = BigDecimal.valueOf(n1);
        BigDecimal bigDecimal2 = BigDecimal.valueOf(n2);
        return bigDecimal.divide(bigDecimal2, 1, RoundingMode.HALF_UP).toString();
    }

    public static void main(String[] args) {
        System.out.println(div(5.0, 2.3));
        System.out.println(5.0/2.3);

        DecimalFormat myFormat = new DecimalFormat("###,###.###");   //实例化DecimalFormat对象
        String output = myFormat.format(123456.789);
        System.out.println(output);

        DecimalFormat myFormat2 = new DecimalFormat();
        myFormat2.applyPattern("#.##%");
        System.out.println(myFormat2.format(0.789999));
    }
}
